/**
 * 飞机类
 * Author：  suyuyi
 * Date：    2017-4-15
 */
cc.Class({
    extends: cc.Component,

    properties: {
        nickname : {
            default : null,
            type    : cc.Label,
            tooltip : "名字"
        },
       avatar : {
            default : null,
            type    : cc.Node,
            tooltip : "皮肤"
        },
        arrow : {
            default : null,
            type    : cc.Node,
            tooltip : "移动方向提示图标"
        },
        _speed: 3
    },
    setSpeed(value){
        this._speed = value;
    },
    setName(nick){
        this.nickname.getComponent(cc.Label).string = nick;
    },
    setAvatar(avatar){
        this.avatar = cc.find(avatar,this.node);
        //.getComponent(cc.Sprite);

    },
    setArrow(arrow){

    },
    // use this for initialization
    onLoad: function () {
        this._isAddSpeed = false;       // 是否开启加速的开始变量
        this.node.active = true;
        this.nickname = cc.find("lab_name",this.node);
        this.nickname.getComponent(cc.Label).string = "suyuyi";
        this.hero = this.node;
        this.avatar = cc.find("spr_avatar",this.node);
        this.arrow = cc.find("spr_avatar/spr_arrow",this.node);
        
        
    },
    heroMove(angle){
        this.hero.setPositionX(this.hero.x + Math.cos( angle ) * this._speed);
        this.hero.setPositionY(this.hero.y + Math.sin( angle ) * this._speed);
        // this.hero.x += Math.cos( angle ) * this._speed;  
        // this.hero.y += Math.sin( angle ) * this._speed;
    },
    heroMove8(angle){
         if(angle > 67.5 && angle < 112.5)  
        {  
            this.hero.y += this._speed;  
        }  
        else if(angle > -112.5 && angle < -67.5)  
        {  
            this.hero.y -= this._speed;  
        }  
        else if(angle < -157.5 && angle > -180 || angle > 157.5 && angle < 180)  
        {  
            this.hero.x -= this._speed;  
        }  
        else if(angle < 0 && angle > -22.5 || angle > 0 && angle < 22.5)  
        {  
            this.hero.x += this._speed;  
        }  
        else if(angle > 112.5 && angle < 157.5)  
        {  
            this.hero.x -= this._speed / 1.414;  
            this.hero.y += this._speed / 1.414;  
        }  
        else if(angle > 22.5 && angle < 67.5)  
        {  
            this.hero.x += this._speed / 1.414;  
            this.hero.y += this._speed / 1.414;  
        }  
        else if(angle > -157.5 && angle < -112.5)  
        {  
            this.hero.x -= this._speed / 1.414;  
            this.hero.y -= this._speed / 1.414;  
        }  
        else if(angle > -67.5 && angle < -22.5)  
        {  
            this.hero.x += this._speed / 1.414;  
            this.hero.y -= this._speed / 1.414;  
        }  
    },
    addBullet(buttlet){
        this.hero.addChild(buttlet);
    },
     /** 设置飞机速度 */
    speed : function() {
        if (this._isAddSpeed){
            this._isAddSpeed = false;
            this.setSpeed(3);
        }
        else {
            this._isAddSpeed = true;
            this.setSpeed(8);
        }
    },
     /**
     * 获取飞机机头的角度
     */
    getPlaneRotation: function(){
        return cc.find("spr_avatar", this.node).rotation;
    }
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
